fix: preserve comments between node and comma in separated lists (#684)#791
Open
todor-a wants to merge 1 commit into
Open
fix: preserve comments between node and comma in separated lists (#684)#791todor-a wants to merge 1 commit into
todor-a wants to merge 1 commit into
Conversation
…int#684) `gen_node_with_separator` emitted the auto-inserted comma immediately after the node, then ran the regular trailing-comments path which only emits same-line comments. Multi-line comments living between the node end and the comma — e.g. foo( a // comment , b); — were therefore captured by `trailing_comments_with_previous` but filtered out by `get_trailing_comments_same_line` and lost. Collect the comma token's leading comments that sit on lines after the node end, mark them handled via `gen_comment_collection`, and emit them after the separator. Result: foo( a, // comment b, ); Applies to anything routed through `gen_node_with_separator`: call arguments, array literals, object literals, function parameters, etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #684.
Transparency note: This PR was prepared with AI assistance (Claude).
Problem
formats to (comment gone):
Root cause
gen_node_with_separator(src/generation/generate.rs:8040) wraps each list element with its separator (comma) via aninner_genclosure.gen_node_with_inner_genthen runs the regular trailing-comments path:gen_comments_as_trailingcallsget_trailing_comments_same_line, which filters to comments whose start line is<= node_end_line. Anything beyond that — i.e. comments that live between the node and the upcoming comma on subsequent lines — is silently dropped. The next sibling'sleading_comments_with_previousdoesn't reach back across the comma, so those comments never reappear.Fix
Before
gen_node_with_inner_genruns, collect the comma token's leading comments (the ones that sit after the node end and afternode_end_line), mark them handled viagen_comment_collection, and emit them after the separator inside the same inner_gen invocation:Output for issue case:
The fix lives in the shared
gen_node_with_separatorso it also covers comments before commas in:Tests
tests/specs/issues/issue0684.txtcovers the issue regression plus mixed line/block comments, array/object/parameter cases. Verified against prettier's comment fixtures (before-comma.js,in-list/dangling-comment-in-list.js,first-argument/first-argument.js).cargo test --releasepasses.